<script setup>
import {saveApi} from "@/api/RoomApi";
import MyForm from "@/components/MyForm.vue";
import {shallowReactive, shallowRef} from "vue";
import {RULE} from "@/const";
import MyHead from "@/components/MyHead.vue";
import MyNav from "@/components/MyNav.vue";
import router from "@/router";

// 表单数据 + 表单规则
let items = shallowRef([
  {'label': '房间名称', 'prop': 'title'},
  {'label': '房间容量', 'prop': 'capacity', 'type': 'number'},
  {'label': '房间地址', 'prop': 'address', 'type': 'textarea'},
  {'label': '房间描述', 'prop': 'info', 'type': 'textarea'},
]);
let data = shallowReactive({
  'capacity': 0,
});
let rules = {
  'info': RULE.COMMON_INFO,
  'title': RULE.COMM_TITLE,
};

function success() {
  setTimeout(() => router.push('/rms/Room'), 1000);
}

</script>

<template>

  <my-nav :items="[
    {'icon': 'User', 'label': '员工管理'},
    {'icon': 'User', 'label': '房间列表', 'url': '/rms/Room'},
    {'icon': 'User', 'label': '添加房间'},
  ]"/>

  <div class="room-insert-body">
    <my-form type="insert"
             :items="items"
             :data="data"
             :rules="rules"
             :api="saveApi"
             :fn="success"
             :span='2'/>
  </div>

</template>

<style scoped lang="scss">
.room-insert-body {
  width: 800px;
  margin-top: 50px;
}
</style>